package com.me.springsimple.security.util;

import org.springframework.security.context.SecurityContextHolder;

import com.me.springsimple.security.user.SpringsimpleUser;

public class SecurityUtils {
	
	
	public static SpringsimpleUser getUser(){
		
		SpringsimpleUser springsimpleUser = null;
		
		if (isNotNull(SecurityContextHolder.getContext().getAuthentication()) && SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof SpringsimpleUser) {
			springsimpleUser = (SpringsimpleUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		} 
		
		return springsimpleUser;
		
	}
	
	public static boolean isNotNull(Object obj){
		boolean b = false;
		if(obj != null){
			b = true;
		}
		return (b);
	}

	public static boolean isNull(Object obj) {
		boolean b = true;
		if(obj != null){
			b = false;
		}
		return (b);
	}
}
